//
// Created by tanke on 23-11-28.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* reversePrefix(char* word, char ch)
{
    int midPos = 0;
    char *result = (char*)malloc(sizeof(char) * (strlen(word) + 1));
    memset(result, 0, sizeof(char) * (strlen(word) + 1));

    for (int i = 0; i < strlen(word); i ++) {
        if (word[i] == ch) {
            midPos = i;
            break;
        }
    }

    for (int i = midPos; i >= 0; i --) {
        result[midPos - i] = word[i];
    }

    for (int i = midPos + 1; i < strlen(word); i ++) {
        result[i] = word[i];
    }

    return result;

}


int main(void)
{
    const char* word = "abcdefd";
    printf("%s\n", reversePrefix(word, 'd'));

    return 0;
}